<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Profile | Freedom Admin</title>
    <!--STYLESHEET-->
    <link rel="stylesheet" th:href="@{/plugins/fonts/material-design-iconic-font/css/material-design-iconic-font.min.css}">
    <link rel="stylesheet" th:href="@{/plugins/waves/waves.min.css}">
    <link rel="stylesheet" th:href="@{/plugins/jquery-tab/css/jquery-tab.css}">
    <!--Bootstrap Stylesheet [ REQUIRED ]-->
    <link th:href="@{/plugins/bootstrap/css/bootstrap.min.css}" rel="stylesheet">
    <!--Nifty Stylesheet [ REQUIRED ]-->
    <link th:href="@{/assets/css/nifty.min.css}" rel="stylesheet">
    <!--Nifty Premium Icon [ DEMONSTRATION ]-->
    <link th:href="@{/assets/css/nifty-icons.min.css}" rel="stylesheet">
    <link th:href="@{/assets/css/nifty-login.min.css}" rel="stylesheet">
    <!-- Bootstrap-fileinput -->
    <link th:href="@{/plugins/bootstrap-fileinput/css/fileinput.min.css}" rel="stylesheet">
</head>

<body>
    <div id="page-content">
    <div class="fixed-fluid">
        <div class="fixed-sm-200 fixed-lg-250 pull-sm-left">
            <div class="panel">
                <!-- Simple profile -->
                <div class="text-center pad-all bord-btm">
                    <div class="pad-ver">
                        <img id="avatar" th:src="@{${currentUser.avatar}}" class="img-lg img-border img-circle" alt="Profile Picture">
                    </div>
                    <h4 class="text-lg text-overflow mar-no" th:text="${currentUser.username}">MoonlightL</h4>
                    <p class="text-sm text-muted" th:text="${currentUser.remark}">remark</p>

                    <button data-target="#upload-modal" data-toggle="modal" class="btn btn-block btn-success" type="button">修改头像</button>
                </div>
                <p class="text-semibold text-main pad-all mar-no">关于我</p>
                <ul class="list-group bg-trans text-sm">

                    <!-- Profile Details -->
                    <li class="list-group-item list-item-sm">
                        <i class="freedom-pli-map-marker-2 icon-lg icon-fw"></i> [[${currentUser.location}]]
                    </li>
                    <li class="list-group-item list-item-sm text-primary text-semibold">
                        <a href="#" class="btn-link text-semibold">
                            <i class="freedom-pli-internet icon-lg icon-fw"></i> [[${currentUser.email}]]
                        </a>
                    </li>
                </ul>
                <div class="pad-hor mar-btm">
                    <small class="text-muted">[[${currentUser.remark}]]</small>
                </div>

                <p class="text-semibold text-main pad-all mar-no">技能</p>
                <ul class="list-inline mar-hor">
                    <li class="tag tag-sm">Java</li>
                    <li class="tag tag-sm">HTML,CSS,Javascript</li>
                    <li class="tag tag-sm">MySQL,Mongodb,Redis</li>
                    <li class="tag tag-sm">RabbitMQ</li>
                </ul>
            </div>
        </div>
        <div class="fluid">
            <div class="bg-trans-light pad-all mar-btm clearfix">
                <hr class="new-section-xs bord-no">
                <div class="col-md-7">
                    <div class="row text-center mar-btm">
                        <div class="col-xs-3">
                            <p class="h4 mar-no"  th:text="${currentUser.loginCount}">1</p>
                            <small class="text-muted">登录次数</small>
                        </div>
                        <div class="col-xs-3">
                            <p class="h4 mar-no" th:text="${currentUser.lastLoginIp}">127.0.0.1</p>
                            <small class="text-muted">上次登录 IP</small>
                        </div>
                        <div class="col-xs-3">
                            <p class="h4 mar-no" th:text="${currentUser.lastLoginTime}"></p>
                            <small class="text-muted">上次登录时间</small>
                        </div>
                    </div>
                </div>
            </div>

            <div class="fixed-fluid">
                <div class="fluid">
                    <!--Default Tabs (Left Aligned)-->
                    <div class="tab-base">
                        <!--Nav Tabs-->
                        <ul class="nav nav-tabs">
                            <li class="active">
                                <a data-toggle="tab" href="#tab-1">基本信息</a>
                            </li>
                            <li>
                                <a data-toggle="tab" href="#tab-2">修改密码</a>
                            </li>
                            <li>
                                <a data-toggle="tab" href="#tab-3">日志记录</a>
                            </li>
                        </ul>
                        <!--Tabs Content-->
                        <div class="tab-content">
                            <div id="tab-1" class="tab-pane fade  active in">
                                <form id="basicDataForm" class="form-horizontal" th:action="@{${updateBasicAction}}" method="post">
                                    <div class="panel-body">
                                        <p class="text-main text-bold">基本资料</p>
                                        <hr>
                                        <div class="form-group">
                                            <label class="col-lg-3 col-sm-2 control-label">用户名</label>
                                            <div class="col-lg-7 col-sm-9">
                                                <input type="text" class="form-control" name="username" th:value="${currentUser.username}" placeholder="用户名" disabled />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-3 col-sm-2 control-label">昵称</label>
                                            <div class="col-lg-7 col-sm-9">
                                                <input type="text" class="form-control" name="nickname" th:value="${currentUser.nickname}" placeholder="昵称" data-bv-notempty="true"
                                                       data-bv-notempty-message="昵称不能为空"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-3 col-sm-2 control-label">性别</label>
                                            <div class="col-lg-7 col-sm-9">
                                                <div class="radio">
                                                    <label>
                                                        <input type="radio" name="gender" value="1" th:checked="${currentUser.gender == 1}"
                                                               data-bv-notempty="true"
                                                               data-bv-notempty-message="性别不能为空" /> 男
                                                    </label>
                                                    <label>
                                                        <input type="radio" name="gender" value="0"  th:checked="${currentUser.gender == 0}"/> 女
                                                    </label>
                                                </div>
                                            </div>
                                        </div>
                                        <p class="text-main text-bold">联系方式</p>
                                        <hr>
                                        <div class="form-group">
                                            <label class="col-lg-3 col-sm-2 control-label">邮箱地址</label>
                                            <div class="col-lg-7 col-sm-9">
                                                <input type="text" class="form-control" name="email" placeholder="邮箱地址" th:value="${currentUser.email}"
                                                       data-bv-notempty="true"
                                                       data-bv-notempty-message="邮箱不能为空"

                                                       data-bv-emailaddress="true"
                                                       data-bv-emailaddress-message="邮箱格式不正确" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-3 col-sm-2 control-label">手机号码</label>
                                            <div class="col-lg-7 col-sm-9">
                                                <input type="text" class="form-control" name="mobile" placeholder="手机号码" th:value="${currentUser.mobile}"
                                                       data-bv-digits="true"
                                                       data-bv-digits-message="手机号码格式不正确" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-3 col-sm-2 control-label">QQ 号码</label>
                                            <div class="col-lg-7 col-sm-9">
                                                <input type="text" class="form-control" name="qq" placeholder="QQ 号码" th:value="${currentUser.qq}"
                                                       data-bv-digits="true"
                                                       data-bv-digits-message="手机号码格式不正确" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-3 col-sm-2 control-label">家庭地址</label>
                                            <div class="col-lg-7 col-sm-9">
                                                <input type="text" class="form-control" name="address" placeholder="家庭地址" th:value="${currentUser.address}"/>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="panel-footer">
                                        <div class="row">
                                            <div class="col-sm-12">
                                                <button class="btn btn-primary" type="submit">提交</button>
                                                <button class="btn btn-default" type="reset">重置</button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div id="tab-2" class="tab-pane fade">
                                <form id="passwordForm" class="form-horizontal" th:action="@{${updatePwdAction}}" method="post">
                                    <div class="panel-body">
                                        <div class="form-group">
                                            <label class="col-lg-3 col-sm-2 control-label">原密码</label>
                                            <div class="col-lg-7 col-sm-9">
                                                <input type="password" class="form-control" id="oldPassword" name="oldPassword" placeholder="原密码"
                                                       data-bv-notempty="true"
                                                       data-bv-notempty-message="原密码不能为空"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-3 col-sm-2 control-label">新密码</label>
                                            <div class="col-lg-7 col-sm-9">
                                                <input type="password" class="form-control" id="newPassword" name="newPassword" placeholder="新密码"
                                                       data-bv-notempty="true"
                                                       data-bv-notempty-message="新密码不能为空"

                                                       data-bv-different="true"
                                                       data-bv-different-field="oldPassword"
                                                       data-bv-different-message="不能与旧密码相同"

                                                       data-bv-identical="true"
                                                       data-bv-identical-field="newPassword"
                                                       data-bv-identical-message="新密码和确认密码不一致"/>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-lg-3 col-sm-2 control-label">确认密码</label>
                                            <div class="col-lg-7 col-sm-9">
                                                <input type="password" class="form-control" id="confirmPassword" name="confirmPassword" placeholder="确认密码"
                                                       data-bv-notempty="true"
                                                       data-bv-notempty-message="确认密码不能为空"

                                                       data-bv-different="true"
                                                       data-bv-different-field="oldPassword"
                                                       data-bv-different-message="不能与旧密码相同"

                                                       data-bv-identical="true"
                                                       data-bv-identical-field="newPassword"
                                                       data-bv-identical-message="新密码和确认密码不一致"/>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="panel-footer">
                                        <div class="row">
                                            <div class="col-sm-12">
                                                <button class="btn btn-primary" type="submit">提交</button>
                                                <button class="btn btn-default" type="reset">重置</button>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </div>
                            <div id="tab-3" class="tab-pane fade" >
                                <div class="panel">
                                    <div class="panel-body">
                                        <!-- Timeline -->
                                        <div id="timeline" class="timeline" style="height: 350px; overflow: auto">
                                            <!-- Timeline header -->
                                            <div class="timeline-header">
                                                <div class="timeline-header-title bg-info">当前</div>
                                            </div>
                                        </div>
                                        <!-- End Timeline -->
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!--===================================================-->
                    <!--End Default Tabs (Left Aligned)-->
                </div>
            </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="upload-modal" role="dialog" tabindex="-1" aria-labelledby="default-modal" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><i class="pci-cross pci-circle"></i></button>
                    <h4 class="modal-title">修改头像</h4>
                </div>
                <div class="modal-body">
                    <div class="panel-body">
                        <input id="upload" type="file" name="avatar" multiple />
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- END SETTINGS -->
<div th:include="common :: script"></div>
<script th:src="@{/plugins/infinite/infinite.js}"></script>
<!--Bootstrap Validator -->
<script th:src="@{/assets/js/bootstrapvalidator.min.js}"></script>
<!-- Bootstrap-fileinput -->
<script th:src="@{/plugins/bootstrap-fileinput/js/fileinput.min.js}"></script>
<script th:src="@{/plugins/bootstrap-fileinput/js/locales/zh.js}"></script>
<script th:src="@{/plugins/freedom-module-file.js}"></script>
<script>
    $(function() {

        $.module.file.init({
            id: "upload",
            uploadUrl: "/core/user/updateAvatar.json",
            dropZoneTitle: "选择一张图片进行上传",
            allowedFileExtensions: ['jpg','jpeg','png'],
            maxImageWidth: 400,
            maxImageHeight: 400,
            maxFileCount: 1,
            callback: function(data) {
                var resp = data.response;
                if (resp.success) {
                    $("#avatar").attr("src", resp.data);
                } else {
                    $.freedom.modal.msg(resp.msg);
                }
            }
        });

        $.freedom.action.save("basicDataForm", null, function (resp) {
            $.freedom.modal.msg(resp.msg, 1, function() {
                window.location.reload();
            });
        });

        $.freedom.action.save("passwordForm", null, function (resp) {
            $.freedom.modal.msg(resp.msg, 1, function() {
                window.location.reload();
            });
        });


        var pageNum = 1;
        var pageSize = 10;
        getLogData(pageNum, pageSize);

        $("#timeline").infinite().on("infinite", function() {
            pageNum = pageNum + 1;
            getLogData(pageNum, pageSize);
        });

        function getLogData(pageNum, pageSize) {
            $.ajax({
                type: "GET",
                url: "/core/log/list.json",
                data: {pageNum: pageNum, pageSize: pageSize, userId: [[${currentUser.id}]]},
                dataType: "JSON",
                success: function(resp) {
                    if (resp.success) {
                        var logArr = resp.data.list;
                        var htmlArr = [];
                        for(var i=0,len=logArr.length; i<len; i++) {
                            var log = logArr[i];
                            htmlArr.push('<div class="timeline-entry">');
                            htmlArr.push('<div class="timeline-stat">');
                            htmlArr.push('<div class="timeline-icon"></div>');
                            htmlArr.push('<div class="timeline-time">'+ log.createTime +'</div>');
                            htmlArr.push('</div><div class="timeline-label">'+ log.remark +'</div></div>');
                        }
                        $("#timeline").append(htmlArr.join(""));
                    }
                }
            });
        }

    });
</script>
</body>
</html>





